<template>
  <div>
    <!-- 设定假期 -->
    <el-dialog
      title="提示"
      :visible.sync="open"
      width="30%"
      @close="dialogclose"
    >
      <template v-if="jiejiari.indexOf(isjiejia) == -1" class="dialog-text">
        <span class="setHoliday">设定为节假日</span>
        <el-input placeholder="请输入节假日名称" v-model="HolidayName"></el-input>
      </template>
      <span v-else>取消节假日</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="bindCloseEvent" class="dialog-text">取 消</el-button>
        <el-button type="primary" @click="bindConfirmEvent">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
/**
 *
 * @description
 * @author 周志琛
 * @date 2021/07/14 09:31:02
 * @property {String} name detail
 * @event
 */

export default {
  name: "Dialog",
  components: {},
  props: ["dialogVisible", "isjiejia", "parentdata"],
  data() {
    return {
      open: false,
      jiejiari: [],
      month_or_year: 0,
      HolidayName:''
    };
  },
  computed: {},
  watch: {
    dialogVisible: {
      handler: function(val) {
        this.open = val;
      },
      immediate: true
    },
    parentdata: function(val) {
      this.jiejiari = val;
    }
  },
  created() {},
  mounted() {},
  methods: {
    dialogclose() {
      this.$emit("update:dialogVisible", false);
    },
    // 取消
    bindCloseEvent() {
      this.$emit("update:dialogVisible", false);
    },
    // 确定
    bindConfirmEvent: async function() {
      this.$emit("update:dialogVisible", false);
      if (this.jiejiari.indexOf(this.isjiejia) == -1) {
        const { data: res1 } = await this.$http.post("/addHoliday", {
          holidayDate: this.isjiejia,type:this.HolidayName
        });
        const { data: res } = await this.$http.post("/updateHoliday", {
          holidayDate: this.isjiejia,
          isDelete: 2,
          type:this.HolidayName
        });
      } else {
        // this.jiejiari.splice(this.jiejiari.indexOf(this.isjiejia),1)
        const { data: res } = await this.$http.post("/updateHoliday", {
          holidayDate: this.isjiejia,
          isDelete: 1,
          type:''
        });
      }
      this.$emit("setjiejia"); //对应getinfo
    }
  }
};
</script>
<style scoped>
.dialog-text {
  font-size: 16px;
}
.setHoliday {
  padding-top: 20px;
  font-weight: 700;
  font-size: 20px;
}
.setHoliday ~ .el-input {
  margin-bottom: 15px;
}
</style>
